package com.cykj.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component  //组件，能被spring扫描到
public class RedisUtils {
    @Autowired
    private RedisTemplate<String,String> template;
    //获取
    public String get(String key){
        return template.opsForValue().get(key);
    }
    //写入
    public  boolean set(String key,String value){
        boolean res = false;
        try {
            template.opsForValue().set(key, value);
            res = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return res;
    }
    //计数器
    public long increase(String key){
        Long increment = template.opsForValue().increment(key);
        return increment;

    }
}
